package com.example.demo.controller;

import com.example.demo.entity.Poetry;
import com.example.demo.service.CollectService;
import com.example.demo.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/collect")
public class CollectController {

    @Resource
    private CollectService collectService;

    @GetMapping("/poetry")
    public Result addCollect(Long userId, Integer poetryId) {
        Integer flag = collectService.insertCollect(userId,poetryId);
        if (flag>0){
            return Result.ok();
        }else {
            return Result.error("插入失败");
        }
    }

    @GetMapping("/delete")
    public Result deleteCollect(Long userId, Integer poetryId) {
        Integer flag = collectService.deleteCollect(userId,poetryId);
        if (flag>0){
            return Result.ok();
        }else {
            return Result.error("删除失败");
        }
    }

    @GetMapping("/getMyCollect")
    public Result getMyCollect(Long userId,Integer pageNo) {
        List<Poetry> poetryList = collectService.selectMyCollectPoetry(userId, pageNo);
        return Result.ok().data("poetryList",poetryList);
    }

}
